package com.vueblog.controller;

import com.alibaba.fastjson.JSONObject;
import com.sun.org.apache.bcel.internal.generic.ACONST_NULL;
import com.vueblog.service.BlogService;
import com.vueblog.service.TypeService;
import com.vueblog.vo.DetailBlog;
import com.vueblog.vo.DetailType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TypeShowController {
    @Autowired
    private TypeService typeService;
    @Autowired
    private BlogService blogService;

    @GetMapping("/getAllTypes")
    public Object getTypesShow(){
        JSONObject jsonObject = new JSONObject();
        List<DetailType> types = typeService.findDetailTypes();
        jsonObject.put("status",200);
        jsonObject.put("types",types);
        return jsonObject;
    }

    @GetMapping("/getShowBlogsByTypeId")
    public Object getBlogsByTypeId(@RequestParam int typeId){
        JSONObject jsonObject = new JSONObject();
        List<DetailBlog> blogs = blogService.findShowBlogsByTypeId(typeId);
        jsonObject.put("blogs",blogs);
        return jsonObject;
    }
}
